package com.wb.mianxiangduixiang.租车系统;

import java.util.Scanner;

/**
 * @author 石小俊
 * @date 2025年07月21日 16:05
 */
public class Test {

    public static void main(String[] args) {
        // 1.进入租车系统,输入客户信息
        System.out.println("************************欢迎来到紫金租车店************************");
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入您的姓名:");
        String name = sc.next();
        System.out.print("请输入您的手机号:");
        String phone = sc.next();
        // 客户对象
        Customer customer = new Customer(name, phone);


        // 2.选择需要租赁的汽车类型(轿车、客车、退出)以及具体的车型(根据选择的类型不同展示不同的车型)
        // 准备一个机动车数组,用于存储所有租赁的车辆信息
        MotorVehicle[] vehicles = new MotorVehicle[100];
        // 准备一个初始下标
        int index = 0;

        // 租车时可以租赁多辆汽车,通过死循环实现
        while (true) {
            String no = null;
            System.out.print("请选择租赁的汽车类型(1.轿车 2.客车 3.退出):");
            int choice = sc.nextInt();
            if (choice == 1) {
                System.out.print("请选择轿车的车型(1.宝马X1 2.奔驰GLC 3.保驰捷帕拉梅拉 4.劳斯莱斯幻影 5.退出):");
                int num = sc.nextInt();
                switch (num) {
                    case 1:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        MotorVehicle vehicle = new Car(no, "宝马", CarConstant.BMW_X1);
                        vehicles[index++] = vehicle;
                        break;
                    case 2:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Car(no, "奔驰", CarConstant.BENZ_GLC);
                        break;
                    case 3:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Car(no, "保时捷", CarConstant.PORSCHE_PANAMERA);
                        break;
                    case 4:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Car(no, "劳斯莱斯", CarConstant.ROLLS_ROYCE_PHANTOM);
                        break;
                    case 5:
                        break;
                    default:
                        System.out.println("错误:您输入的选项有误!");
                        break;
                }
            } else if (choice == 2) {
                System.out.print("请选择客车的车型(1.20座考斯特 2.25座奔驰凌特 3.35座宇通客车 4.45座金龙客车 5.退出):");
                int num = sc.nextInt();
                switch (num) {
                    case 1:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Bus(no, "考斯特", 20);
                        break;
                    case 2:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Bus(no, "奔驰", 25);
                        break;
                    case 3:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Bus(no, "宇通", 35);
                        break;
                    case 4:
                        System.out.print("请输入车牌号:");
                        no = sc.next();
                        vehicles[index++] = new Bus(no, "金龙", 45);
                        break;
                    case 5:
                        break;
                    default:
                        System.out.println("错误:您输入的选项有误!");
                        break;
                }
            } else if (choice == 3) {
                // 退出循环
                break;
            } else {
                System.out.println("错误:您输入的选项有误,请重新输入!");
            }
        }

        // 3.车辆选择完成之后指定租赁的天数
        System.out.print("请输入这些机动车租赁的天数:");
        int day = sc.nextInt();

        // 4.展示客户租赁的所有车辆的车牌与品牌信息
        System.out.println("恭喜" + customer.getName() + "客户,租车成功,您租赁的车辆信息如下:");
        System.out.println("-------------------------------------------");
        // 车牌号          品牌
        // 苏A0001       宝马
        // xxx          xxx
        System.out.println("车牌号\t\t品牌");
        // 此处遍历的是已租的车辆,而不是整个数组
        // 可以在遍历车辆的时候,每遍历一辆车就将车辆租车计算到总租金中
        double sum = 0.0;
        for (int i = 0; i < index; i++) {
            System.out.println(vehicles[i].getNo() + "\t\t" + vehicles[i].getBrand());
            sum += vehicles[i].rent(day);
        }
        System.out.println("-------------------------------------------");
        // 5.打印共租赁了几辆机动车,租赁了多少天,总租金多少元
        System.out.println("共租赁了" + index + "辆机动车,租赁了" + day + "天,总租金:" + sum);
    }

}
